package o;

import android.text.TextUtils;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.updatemanager.ui.cardkit.bean.IgnoreUpdateTitleCardBean;
import com.huawei.appgallery.updatemanager.ui.cardkit.bean.UpdateRecordCardBean;
import java.util.ArrayList;
import java.util.List;

abstract class dbi {
    long ʽ;
    int ˊ;
    long ˋ;
    int ˎ;
    int ˏ;
    long ॱ;
    private List<ApkUpgradeInfo> ᐝ = new ArrayList(16);

    @NonNull
    protected abstract List<ApkUpgradeInfo> ˏ();

    dbi() {
    }

    protected boolean ˏ(cia o_cia) {
        chz ॱ = o_cia.ॱ(this.ˋ);
        if (ॱ == null || ॱ.ˎ == null || ॱ.ˎ.isEmpty()) {
            return false;
        }
        return ((IgnoreUpdateTitleCardBean) ॱ.ˎ.get(0)).isIgnoreCardshow;
    }

    public int ˊ() {
        return this.ᐝ.size();
    }

    @MainThread
    public void ˋ() {
        this.ᐝ.clear();
        this.ᐝ.addAll(ˏ());
    }

    public void ˏ(@NonNull cia o_cia, boolean z) {
        ˎ(o_cia, dba.ˏ(this.ᐝ, z));
    }

    @Nullable
    public chz ˊ(cia o_cia) {
        return o_cia.ॱ(this.ॱ);
    }

    public boolean ॱ(cia o_cia) {
        if (o_cia == null) {
            czi.ˎ.ˊ("UpdateRecordManagerBase", "toggleExpandStatus error, cardDataProvider is null.");
            return false;
        }
        boolean ᐝ = ᐝ(o_cia);
        if (this.ʽ == 0) {
            return ᐝ;
        }
        ॱ(ˎ(o_cia, this.ʽ), ᐝ);
        return ᐝ;
    }

    private boolean ᐝ(@NonNull cia o_cia) {
        chz ˊ = ˊ(o_cia);
        chz ˎ = ˎ(o_cia);
        if (!(ˎ == null || ˎ.ˎ == null || ˎ.ˎ.isEmpty())) {
            IgnoreUpdateTitleCardBean ignoreUpdateTitleCardBean = (IgnoreUpdateTitleCardBean) ˎ.ˎ.get(0);
            ignoreUpdateTitleCardBean.isIgnoreCardshow = !ignoreUpdateTitleCardBean.isIgnoreCardshow;
            if (ॱ(ˊ)) {
                for (CardBean cardBean : ˊ.ˎ) {
                    if (cardBean != null) {
                        ((UpdateRecordCardBean) cardBean).ˊ(ignoreUpdateTitleCardBean.isIgnoreCardshow);
                    }
                }
                if (ignoreUpdateTitleCardBean.isIgnoreCardshow) {
                    return true;
                }
            }
        }
        return false;
    }

    public void ˋ(@NonNull cia o_cia) {
        ॱ(o_cia, ˋ(o_cia, ˏ(o_cia)));
    }

    @Nullable
    public chz ˎ(cia o_cia) {
        return o_cia.ॱ(this.ˋ);
    }

    private void ॱ(cia o_cia, List<CardBean> list) {
        chz ˎ = ˎ(o_cia, this.ˋ);
        chz ˎ2 = ˎ(o_cia, this.ॱ);
        chz ˎ3 = ˎ(o_cia, this.ʽ);
        if (ˎ != null) {
            List list2;
            boolean z;
            if (list == null || list.isEmpty()) {
                list2 = null;
                list = null;
            } else if (ˎ.ˎ == null || ˎ.ˎ.isEmpty()) {
                list2 = new ArrayList();
                list2.add(new IgnoreUpdateTitleCardBean());
            } else {
                list2 = new ArrayList(ˎ.ˎ);
            }
            ˎ.ˊ(list2);
            if (list != null) {
                ˊ(list, ˎ2);
                ˎ2.ˊ(list);
            } else {
                ˎ2.ˊ(null);
            }
            if (!(list2 == null || list2.isEmpty())) {
                CardBean cardBean = (CardBean) list2.get(0);
                if (cardBean instanceof IgnoreUpdateTitleCardBean) {
                    z = ((IgnoreUpdateTitleCardBean) cardBean).isIgnoreCardshow;
                    ॱ(ˎ3, z);
                }
            }
            z = false;
            ॱ(ˎ3, z);
        }
    }

    private void ॱ(chz o_chz, boolean z) {
        if (o_chz != null) {
            List list = null;
            if (z) {
                list = new ArrayList(1);
                list.add(new BaseDistCardBean());
            }
            o_chz.ˊ(list);
        }
    }

    private chz ˎ(cia o_cia, long j) {
        if (j != 0) {
            return o_cia.ॱ(j);
        }
        return null;
    }

    private List<CardBean> ˋ(cia o_cia, boolean z) {
        if (o_cia.ॱ(this.ॱ) != null) {
            return dba.ˏ(this.ᐝ, z);
        }
        czi.ˎ.ˊ("UpdateRecordManagerBase", "getUpdateRecordBeanList, recordItems == null");
        return null;
    }

    private void ˎ(cia o_cia, @Nullable List<CardBean> list) {
        int i;
        List list2;
        IgnoreUpdateTitleCardBean ignoreUpdateTitleCardBean = null;
        if (list == null || list.isEmpty()) {
            i = 0;
            list2 = null;
        } else {
            List arrayList = new ArrayList();
            ignoreUpdateTitleCardBean = new IgnoreUpdateTitleCardBean();
            arrayList.add(ignoreUpdateTitleCardBean);
            i = list.size();
            list2 = arrayList;
        }
        if (this.ˋ != 0) {
            o_cia.ˋ(this.ˋ, this.ˊ, 1, null).ˊ(list2);
        }
        if (this.ॱ != 0) {
            o_cia.ˋ(this.ॱ, this.ˏ, i, null).ˊ(list);
        }
        if (this.ʽ != 0) {
            List list3;
            if (ignoreUpdateTitleCardBean == null || !ignoreUpdateTitleCardBean.isIgnoreCardshow) {
                list3 = null;
            } else {
                list3 = new ArrayList(1);
                list3.add(new BaseDistCardBean());
            }
            o_cia.ˋ(this.ʽ, this.ˎ, 1, null).ˊ(list3);
        }
    }

    private boolean ॱ(chz o_chz) {
        return (o_chz == null || o_chz.ˎ == null || o_chz.ˎ.size() <= 0) ? false : true;
    }

    private void ˊ(List<CardBean> list, chz o_chz) {
        if (o_chz != null) {
            Object ॱـ;
            String str = "";
            for (CardBean cardBean : o_chz.ˏ()) {
                if ((cardBean instanceof UpdateRecordCardBean) && ((UpdateRecordCardBean) cardBean).ꞌ()) {
                    ॱـ = cardBean.ॱـ();
                    break;
                }
            }
            String str2 = str;
            if (!TextUtils.isEmpty(ॱـ)) {
                for (CardBean cardBean2 : list) {
                    if ((cardBean2 instanceof UpdateRecordCardBean) && ॱـ.equals(cardBean2.ॱـ())) {
                        ((UpdateRecordCardBean) cardBean2).ॱ(true);
                        return;
                    }
                }
            }
        }
    }
}
